//import com.java.demo.*;
import com.java.demo.controller.UserController;
import com.java.demo.controller.UserController2;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 启动类
 */
public class App {
    public static void main(String[] args) {
        // 1.得到 Spring 容器
        ApplicationContext context =
                new ClassPathXmlApplicationContext("spring-config.xml");

        UserController2 controller2 = context.getBean("userController2",
                UserController2.class);
        controller2.sayHi();

//        User user = context.getBean("user1", User.class);
        // Bean 命名规则和五大类注解的命名规则不同，默认情况下， @Bean存储的是 对象的名称 = 方法名
//        User user = context.getBean("getUserByName", User.class);
//        System.out.println(user.getUsername());

//        UserController controller = context.getBean("userController",
//                UserController.class);
//        controller.sayHi();

//        // 2. 得到 bean 对象
        // 默认情况下：原类名首字母小写就能获取到 Bean 对象
//        StudentController studentController =
//                context.getBean("studentController", StudentController.class);
//
//        // 3. 得到 bean 对象
//        studentController.sayHi();

        // 特殊情况下：原类名第一个和第二个字母都大写，需要使用原类名来获取 Bean 对象
//        SController sController = context.getBean("SController", SController.class);
//        sController.sayHi();

//        StudentController2 studentController2 =
//                context.getBean("studentController2", StudentController2.class);
//        studentController2.sayHi();

//        StudentController3 studentController3 =
//                context.getBean("studentController3", StudentController3.class);
//        studentController3.sayHi();

//        StudentController4 studentController4 =
//                context.getBean("studentController4", StudentController4.class);
//        studentController4.sayHi();

//        StudentController5 studentController5 =
//                context.getBean("studentController5", StudentController5.class);
//        studentController5.sayHi();

//        UserService userService = context.getBean("userService", UserService.class);
//        userService.sayHi();

    }
}
